package com.shine.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.shine.entity.User;
import com.shine.info.UserInfo;
import com.shine.request.UserPageRequest;
import com.shine.request.UserUpdateRequest;
import com.shine.service.UserService;
import com.shine.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @author huihui
 * @date 2025/10/11 15:44
 * @description UserController
 */
@Slf4j
@Tag(name = "用户表 Controller", description = "用户表 Controller")
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Resource
    private UserService userService;

    @GetMapping("/page")
    @Operation(summary = "用户表分页查询")
    public Result<IPage<UserInfo>> pageQueryUser(UserPageRequest request) {
        IPage<UserInfo> userPage = userService.pageQuery(request);
        return success(userPage);
    }

    @GetMapping("/get/{id}")
    @Operation(summary = "用户表详情查询")
    public Result<UserInfo> getUserById(@PathVariable("id") Long id) {
        UserInfo user = userService.getById(id);
        return success(user);
    }

    @GetMapping("/delete/{id}")
    @Operation(summary = "根据ID删除用户表")
    public Result<Boolean> deleteUserById(@PathVariable("id") Long id) {
        Boolean flag = userService.deleteById(id);
        return success(flag);
    }

    @PostMapping("/update")
    @Operation(summary = "修改用户")
    public Result<Boolean> updateUser(@RequestBody UserUpdateRequest request) {
        Boolean flag = userService.updateUser(request);
        return success(flag);
    }

}